<template>
  <view class="threePage">
    <view class="top">
      <img style="width: 80%; margin: 0 auto"
        src="https://nfzjszlb.jst.zj.gov.cn/serverfile/zheliban/icon/YPC/11.png" />
      <p>
        <span style="
            width: 31%;
            display: inline-block;
            text-align: left;
            padding-left: 0%;
          ">鉴定申请</span>
        <span style="width: 31%; display: inline-block; text-align: center">合同签订</span>
        <span style="
            width: 31%;
            display: inline-block;
            text-align: center;
            padding-left: 12%;
          ">房屋整治</span>
      </p>
    </view>
    <view v-for="(item, index) in formData" :key="index">
      <view class="title">
        {{ item.name }}
      </view>
      <u-cell-group v-for="(it, ind) in item.chirld" :key="ind">
        <span v-if="it.key" style="
            color: #ff0000;
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
          ">*</span>
        <u-cell v-if="it.key" :value="model1[index][it.key]" :title="it.name" isLink>
        </u-cell>
        <u-button v-else @click="handleGotonext1(index)" style="width: 100%; margin: 1rem 0" text="确定" size="large"
          color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"></u-button>
      </u-cell-group>
    </view>
  </view>
</template>

<script>
import {
  ECAOpenDataView,
} from "@/common/utils/api.js";
export default {
  data() {
    return {
      formData: [
      ],
      model1: [],
      model2: [],
    };
  },
  methods: {
    handleGotonext1(data) {
      console.log(data)
      uni.navigateTo({
        url: "/pages/applyAppraisal/applyAppraisal?model1=" + JSON.stringify(this.model1[data])+'&model2='+JSON.stringify(this.model2[data]),
      });
    },
    getXianOpenDataView1: async function (data, data2, data1) {
      let time = Date.now();
      const res = await ECAOpenDataView(
        data2,
        JSON.stringify([{ field: "PID", value: data }]),
        time
      );
      this.formData.forEach((it,index) => {
        it.chirld.forEach((item)=>{
          switch (data1) {
          case "1":
            if (item.keys == "X") {
              item.actions.push(res.Data);
              item.actions[0].forEach((items) => {
                items.keys = "X";
                items.key = "SSX";
                items.dataguid = "24d07248-ba49-4b82-9029-b5eccaff179d";
              });
            }
            break;
          case "2":
            if (item.keys == "Z") {
              item.actions.push(res.Data);
              //赋值
              item.actions[0].forEach((items) => {
                if (items.CITYCODE == this.model2[index].SSZ) {
                  console.log(this.model1[index])
                  this.model1[index]['SSZ'] = items.CITYNAME
                }
                items.keys = "Z";
                items.key = "SSZ";
                items.dataguid = "d3aaed7c-84ee-4de3-b70e-07fe188cdc8e";
              });
            }
            break;
          case "3":
            if (item.keys == "C") {
              item.actions.push(res.Data);
              item.actions[0].forEach((items) => {
                if (items.CITYCODE == this.model2[index].SSC) {
                  console.log(this.model1[index])
                  this.model1[index]['SSC'] = items.CITYNAME
                }
                items.keys = "C";
                items.key = "SSC";
                items.dataguid = "";
              });
            }
            break;
        }
        })
      });
    },
  },
  onLoad(options) {
    let data = (JSON.parse(options.data))
    data.forEach((item, index) => {
      //先push
      var obj = {}
      obj.chirld = [
        {
          name: "所属市",
          key: "SSS",
          required: true,
          title: false,
          XIALA: true,
          keyName: "CITYNAME",
          keys: "S",
          actions: [],
        },
        {
          name: "所属县(区)",
          key: "SSX",
          required: true,
          title: false,
          XIALA: true,
          keys: "X",
          keyName: "CITYNAME",
          dataguid: "77fdf2b0-0eb5-4243-a0a4-6185299ccd34",
          actions: [],
        },
        {
          name: "所属镇",
          key: "SSZ",
          required: true,
          XIALA: true,
          keyName: "CITYNAME",
          title: false,
          keys: "Z",
          dataguid: "e9c98787-4966-4365-80b0-c1cc678c6f85",
          actions: [],
        },
        {
          name: "所属村",
          key: "SSC",
          required: true,
          XIALA: true,
          keyName: "CITYNAME",
          title: false,
          dataguid: "24d07248-ba49-4b82-9029-b5eccaff179d",
          keys: "C",
          actions: [],
        },
        {
          name: "房屋地址",
          key: "FWDZ",
          required: true,
          XIALA: false,
          title: false,
          keys: "FWDZ",
        },
        {
          name: "建筑层数",
          key: "JZCS",
          required: false,
          title: false,
          XIALA: true,
          keyName: "DICNAME",
          keys: "JZCS",
          actions: [],
        },
        {
          name: "建造年份",
          key: "JZNF",
          required: false,
          title: false,
          keyName: "DICNAME",
          XIALA: true,
          keys: "JZNF",
          actions: [],
        },
        {
          name: "确定",
          key: ""
        },
      ]
      obj.name = '房屋' + (Number(index))
      this.formData.push(obj)
      var newobj = {}
      newobj.FWDZ = item.XXDZ
      newobj.JZCS = item.JZCS
      newobj.JZNF = item.JSNF
      newobj.SSZ = ""
      newobj.SSC = ""
      newobj.SSS = item.cityName
      newobj.SSX = item.countryName
      this.model1.push(newobj)
      //model2 需要换成数组
      let newobj2 = {}
      newobj2.SSS = item.cityCode.substring(0, 4) + '00000000'
      this.getXianOpenDataView1(newobj2.SSS, '77fdf2b0-0eb5-4243-a0a4-6185299ccd34', '1')
      newobj2.SSX = item.cityCode.substring(0, 6) + '000000'
      this.getXianOpenDataView1(newobj2.SSX, '24d07248-ba49-4b82-9029-b5eccaff179d', '2')
      newobj2.SSZ = item.cityCode.substring(0, 9) + '000'
      this.getXianOpenDataView1(newobj2.SSZ, 'd3aaed7c-84ee-4de3-b70e-07fe188cdc8e', '3')
      newobj2.SSC = item.cityCode
      this.model2.push(newobj2)
    })
    console.log(this.model1)
    if (ZWJSBridge) {
      ZWJSBridge.setTitle({
        title: "房屋选择",
      })
        .then((res) => { })
        .catch((err) => { });
    }
  }
};
</script>

<style lang="scss" scoped>
.threePage {
  height: 100vh;
  overflow-y: auto;
  padding: 0 20rpx;

  .title {
    padding: 0.6rem;
    font-size: 1.1rem;
    font-weight: 800;
  }

  .top {
    height: 30px;
    background: #ffffff;
    margin-bottom: 20px;
    padding-top: 25px;
    text-align: center;

    .origin {
      width: 22px;
      height: 22px;
      background: #007aff;
      border-radius: 50%;
      display: inline-block;
    }

    .line {
      width: 20vw;
      /*height: 1px;*/
      border: 1px dashed #007aff;
      display: inline-block;
    }
  }
}
</style>
